import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Clase Axe, es una subclase de la clase Weapon, tiene variables para saber en que direccion se dirige,
 * cuando debe de comenzar a caer, y para guardar las diferentes imagenes que hacen parecer que gira al moverse.
 * 
 * @author (Manuel) 
 * @version (1.0)
 */
public class Axe extends Weapon
{
   
    private boolean goRight;
    private int contFall;
    private GreenfootImage im1;
    private GreenfootImage im2;
    private GreenfootImage im3;
    private GreenfootImage im4;
    
    /**
     * Constructor of the class Axe. It receives the direction the axe will take, it sets the counter for the fall
     * it loads the images from the files to their varibles.
       */
    public Axe(boolean der)
    {
        goRight=der;
        contFall=0;
        im1=new GreenfootImage("axe.png");
        im2=new GreenfootImage("axe2.png");
        im3=new GreenfootImage("axe3.png");
        im4=new GreenfootImage("axe4.png");
    }
    
    /**
     * The Axe just fall from a distance in  a direction defined int the constructor.
       */
    public void act() 
    {
        move();
    }    
    
    /**
     * it's the method that move the Axe in a certain direction. it's uses the method setLocation from the class Actor
     * to move the Axe, and changes the image of it with the method setimage. This method remoces the images from the world 
     * when the axe has fallen and is out of the screen.
       */
    public void move()
    {
        if(goRight)
        {
          setLocation(getX()+10,getY()+3);
          if(contFall<8)
             contFall++;
          else contFall=0;
          switch(contFall)
          {
              case 0:setImage(im1);
              break;
              case 2:setImage(im2);
              break;
              case 4:setImage(im3);
              break;
              case 6:setImage(im4);
              break;
            }
        }else
        {
            setLocation(getX()-10,getY()+3);
          if(contFall<8)
             contFall++;
          else contFall=0;
          switch(contFall)
          {
              case 0:setImage(im1);
              break;
              case 2:setImage(im2);
              break;
              case 4:setImage(im3);
              break;
              case 6:setImage(im4);
              break;
            }
        }
        if(getY()>getWorld().getHeight())
          ((CaveWorld)(getWorld())).deleteAxe(this);
    }
}
